home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 34.3 KB | 1,303 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGDev.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #if defined(FW_PROFILER_CALLS) && defined(__MWERKS__)
- #pragma profile on
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- #ifndef FWODEXCE_H
- #includ "FWODExce.h"
- #endif
-
- #ifndef PRGDEV_H
- #include "PRGDev.h"
- #endif
-
- #ifndef SLREGION_H
- #include "SLRegion.h"
- #endif
-
- #ifndef FWPAT_H
- #include "FWPat.h"
- #endif
-
- #ifndef SLGRGLOB_H
- #include "SLGrGlob.h"
- #endif
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWFONT_H
- #include "FWFont.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef PRSHATTR_H
- #include "PRShAttr.h"
- #endif
-
- #ifndef PRGRUTIL_H
- #include "PRGrUtil.h"
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__LOWMEM__)
- #include <LowMem.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__PRINTING_)
- #include <Printing.h>
- #endif
-
- #ifdef FW_BUILD_MAC
- #include <stdio.h> // Need sprintf for PostScript clipping
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- // ----- Standard C Includes -----
-
- #include <math.h>
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_Device
- #endif
-
- FW_DEFINE_AUTO(FW_CPrivGraphicsDevice)
-
- //========================================================================================
- // Macros
- //========================================================================================
-
- #ifdef FW_BUILD_WIN
-
- #define FW_CHECK_PLATFORM_CANVAS \
- FW_ASSERT(fPlatformCanvas != NULL);
-
- #endif
-
- #ifdef FW_BUILD_MAC
-
- #define FW_CHECK_PLATFORM_CANVAS \
- FW_ASSERT(fPlatformCanvas != NULL); \
- FW_ASSERT(fPlatformCanvas == FW_QDGlobals.thePort);
-
- #endif
-
- //========================================================================================
- // class FW_CPrivGraphicsDevice
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::FW_CPrivGraphicsDevice
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGraphicsDevice::FW_CPrivGraphicsDevice(ODCanvas* odCanvas) :
- fODCanvas(odCanvas),
- fPlatformCanvas(NULL),
- #ifdef FW_BUILD_MAC
- fPattern(FW_NEW(FW_CPrivBWPatternRep, (FW_kBlackPat))),
- #endif
- fOpenDeviceCount(0),
- fSuspended(FALSE),
- fContext(NULL),
- fResolution(FW_kZeroPoint)
- {
- FW_ASSERT(fODCanvas != NULL);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::FW_CPrivGraphicsDevice
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGraphicsDevice::FW_CPrivGraphicsDevice(ODPlatformCanvas platformCanvas) :
- fODCanvas(NULL),
- fPlatformCanvas(platformCanvas),
- #ifdef FW_BUILD_MAC
- fPattern(FW_NEW(FW_CPrivBWPatternRep, (FW_kBlackPat))),
- #endif
- fOpenDeviceCount(0),
- fSuspended(FALSE),
- fContext(NULL),
- fResolution(FW_kZeroPoint)
- {
- FW_ASSERT(fPlatformCanvas != NULL);
- FW_END_CONSTRUCTOR
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::~FW_CPrivGraphicsDevice
- //---------------------------------------------------------------------------------------
-
- FW_CPrivGraphicsDevice::~FW_CPrivGraphicsDevice()
- {
- FW_START_DESTRUCTOR
- FW_ASSERT(fOpenDeviceCount == 0);
- FW_ASSERT(!fSuspended);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::GetResolution
- //----------------------------------------------------------------------------------------
- FW_CPoint FW_CPrivGraphicsDevice::GetResolution() const
- {
- if (fResolution == FW_kZeroPoint)
- {
- FW_ASSERT(fPlatformCanvas != NULL);
-
- FW_CPrivGraphicsDevice* self = (FW_CPrivGraphicsDevice *) this;
-
- #ifdef FW_BUILD_WIN
- self->fResolution.x = FW_IntToFixed(::GetDeviceCaps(fPlatformCanvas, LOGPIXELSX));
- self->fResolution.y = FW_IntToFixed(::GetDeviceCaps(fPlatformCanvas, LOGPIXELSY));
- #endif
- #ifdef FW_BUILD_MAC
- self->fResolution.x = FW_IntToFixed(72);
- self->fResolution.y = FW_IntToFixed(72);
- #endif
- }
-
- return fResolution;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetResolution
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SetResolution(FW_Fixed x, FW_Fixed y)
- {
- fResolution.x = x;
- fResolution.y = y;
- }
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::IsMetaFileCanvas
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivGraphicsDevice::IsMetaFileCanvas() const
- {
- FW_ASSERT(fPlatformCanvas);
- return ::GetDeviceCaps(fPlatformCanvas, TECHNOLOGY) == DT_METAFILE;
- }
- #endif
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::OpenDevice
- //---------------------------------------------------------------------------------------
-
- FW_SPrivDeviceState* FW_CPrivGraphicsDevice::OpenDevice(Environment *ev, FW_SGraphicContext* context)
- {
- // [KVV] FW_ASSERT(!fSuspended);
-
- FW_ASSERT(fContext == NULL);
- fContext = context;
-
- // ----- Get the platform canvas -----
- if (fPlatformCanvas == NULL)
- {
- #ifdef FW_BUILD_WIN
- fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODWindows);
- #endif
- #ifdef FW_BUILD_MAC
- fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODQuickDraw);
- #endif
- }
- FW_ASSERT(fPlatformCanvas != NULL);
-
- // ----- Save first the current state -----
- FW_SPrivDeviceState* deviceState = GetState(); // GetState set the port
-
- // ----- Reset Settings -----
- if (fOpenDeviceCount == 0)
- {
- // Update the resolution
- FW_CPoint res = GetResolution();
-
- #ifdef FW_BUILD_WIN
- fTextColor = ::GetTextColor(fPlatformCanvas);
- fBkColor = ::GetBkColor(fPlatformCanvas);
- fPenSize.Set(0, 0);
-
- ::SetMapMode(fPlatformCanvas, MM_TEXT);
- #endif
- #ifdef FW_BUILD_MAC
- ResetSettings();
- fMacPostScriptClip = FALSE;
- #endif
- }
-
- fSuspended = FALSE; // we are opening it so it is not suspended
- fOpenDeviceCount++;
-
- // ----- Set the origin offset -----
- UpdateOriginForContext(ev);
-
- return deviceState;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_ColorPenNormal
- //---------------------------------------------------------------------------------------
-
- static void FW_ColorPenNormal()
- {
- ::PenNormal();
- FW_PrivMacSetStdColors();
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::CloseDevice
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::CloseDevice(Environment *ev, FW_SPrivDeviceState* deviceState)
- {
- FW_UNUSED(ev);
- // ----- [LSD] can't check "fPlatformCanvas == FW_QDGlobals.thePort" here because we may
- // have already opened another window
- // FW_CHECK_PLATFORM_CANVAS
- FW_ASSERT(fPlatformCanvas != NULL);
-
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- #ifdef FW_BUILD_MAC
- ::SetGWorld((CGrafPtr)fPlatformCanvas, NULL);
-
- // ----- [HLX] OpenDoc Bug ????
- // I should not have to restore the Grafport but
- // ODFacet::DrawActiveBorder doesn't reset the foreground
- // and background color correctly so....
- FW_ColorPenNormal();
- // ----- [HLX] OpenDoc Bug ????
- #endif
-
- // ----- Restore origin and clip -----
- #ifdef FW_BUILD_WIN
- ::SetWindowOrgEx(fPlatformCanvas, deviceState->fWindOrg.x, deviceState->fWindOrg.y, NULL);
- ::SetMapMode(fPlatformCanvas, deviceState->fMapMode);
- #endif
- #ifdef FW_BUILD_MAC
- if (fMacPostScriptClip)
- MacEndPostScriptClip();
-
- ::SetOrigin(deviceState->fOrigin.h, deviceState->fOrigin.v);
-
- if (FW_MacIsColorPort(FW_QDGlobals.thePort)) // [LW7]
- {
- ::SetClip(deviceState->fClip);
- }
-
- ::FW_DisposeRegion(deviceState->fClip);
- deviceState->fClip = NULL;
-
- // ----- Restore previous port -----
- ::SetGWorld((CGrafPtr)deviceState->fPreviousPlatformCanvas, NULL);
- #endif
-
- #ifdef FW_BUILD_MAC
- // ----- Restore the suspended flag
- // [KVV] CloseDevice should set fSuspended to FALSE!
- fSuspended = deviceState->fSuspended;
- #endif
-
- // ----- Decrement fOpenDeviceCount -----
- fOpenDeviceCount--;
-
- // ----- If fOpenDeviceCount == 0 the device is not used anymore.
- if (fOpenDeviceCount == 0)
- {
- #ifdef FW_BUILD_WIN
- // ----- Unselect our object -----
- fGDIPen.UnselectObject(fPlatformCanvas);
- fGDIBrush.UnselectObject(fPlatformCanvas);
- fGDIFont.UnselectObject(fPlatformCanvas);
-
- // ----- Reset also textColor, bkColor etc to their default value -----
- ::SetTextColor(fPlatformCanvas, RGB(0x00, 0x00, 0x00));
- ::SetBkColor(fPlatformCanvas, RGB(0xFF, 0xFF, 0xFF));
- ::SetROP2(fPlatformCanvas, R2_COPYPEN);
- ::SetBkMode(fPlatformCanvas, OPAQUE);
- #endif
-
- if (fODCanvas != NULL)
- {
- #ifdef FW_BUILD_WIN
- fODCanvas->ReleasePlatformCanvas(ev);
- #endif
- }
-
- fPlatformCanvas = NULL;
- }
-
- // ----- We don't need the deviceState anymore -----
- delete deviceState;
-
- // ----- Not valid anymore -----
- fContext = NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::GetState
- //---------------------------------------------------------------------------------------
-
- FW_SPrivDeviceState* FW_CPrivGraphicsDevice::GetState()
- {
- FW_ASSERT(fPlatformCanvas != NULL);
- FW_SPrivDeviceState* deviceState = new FW_SPrivDeviceState;
-
- #ifdef FW_BUILD_WIN
- deviceState->fMapMode = ::GetMapMode(fPlatformCanvas);
- ::GetWindowOrgEx(fPlatformCanvas, &deviceState->fWindOrg);
- #endif
- #ifdef FW_BUILD_MAC
- // ----- Save previous grafport -----
- ::GetPort(&deviceState->fPreviousPlatformCanvas);
- FW_ASSERT(deviceState->fPreviousPlatformCanvas != NULL);
-
- // ----- Set the new grafport -----
- ::SetGWorld((CGrafPtr)fPlatformCanvas, NULL);
-
- // ----- Save the origin and the clip of our port
- deviceState->fOrigin.h = fPlatformCanvas->portRect.left;
- deviceState->fOrigin.v = fPlatformCanvas->portRect.top;
-
- deviceState->fClip = ::FW_CopyRegion(fPlatformCanvas->clipRgn);
-
- deviceState->fSuspended = fSuspended;
- #endif
-
- return deviceState;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::Suspend
- //---------------------------------------------------------------------------------------
-
- FW_SPrivSuspendResumeState* FW_CPrivGraphicsDevice::Suspend()
- {
- // [KVV] FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0); // Should not have to Suspend if not opened
-
- // [KVV] When called from the drag manager, the current port has already been changed
- // FW_CHECK_PLATFORM_CANVAS
-
- #ifdef FW_BUILD_WIN
- FW_SPrivSuspendResumeState* deviceState = new FW_SPrivSuspendResumeState;
- deviceState->fSavedDC = ::SaveDC(fPlatformCanvas);
- #endif
- #ifdef FW_BUILD_MAC
- FW_SPrivSuspendResumeState* deviceState = GetState();
- #endif
-
- deviceState->fSavedContext = fContext;
- fContext = NULL;
-
- fSuspended = TRUE;
-
- #ifdef FW_BUILD_MAC
- // Look like some part don't reset the grafport so....
- GrafPtr port;
- ::GetPort(&port);
- ::SetGWorld((CGrafPtr)fPlatformCanvas, NULL);
-
- FW_ColorPenNormal();
-
- ::SetGWorld((CGrafPtr)port, NULL);
- #endif
-
- return deviceState;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::Resume
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::Resume(FW_SPrivSuspendResumeState* deviceState)
- {
- // [KVV] FW_ASSERT(fSuspended);
- FW_ASSERT(fPlatformCanvas != NULL);
-
- FW_ASSERT(fContext == NULL);
- fContext = deviceState->fSavedContext;
-
- #ifdef FW_BUILD_WIN
- ::RestoreDC(fPlatformCanvas, deviceState->fSavedDC);
- #endif
- #ifdef FW_BUILD_MAC
- // [KVV] Drag and drop (also see comment in Suspend)
- // FW_ASSERT(deviceState->fPreviousPlatformCanvas == fPlatformCanvas);
-
- ::SetGWorld((CGrafPtr)fPlatformCanvas, NULL); // The port may have changed
-
- ::SetOrigin(deviceState->fOrigin.h, deviceState->fOrigin.v);
- ::SetClip(deviceState->fClip);
- ::FW_DisposeRegion(deviceState->fClip);
- deviceState->fClip = NULL;
-
- fSuspended = deviceState->fSuspended; // [KVV] Resume should "fSuspended = FALSE"
-
- // ----- We need to reset our settings
- ResetSettings();
- #endif
-
- // ----- We don't need the suspendResumeState anymore -----
- delete deviceState;
-
- // ----- We are not suspended anymore -----
- fSuspended = FALSE;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::CanvasChanged
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::CanvasChanged(Environment* ev, ODCanvas* newCanvas)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount == 0);
- FW_ASSERT(fODCanvas != NULL); // Should not change the canvas if didn't have a canvas already
-
- #ifdef FW_BUILD_WIN
- if(fPlatformCanvas != NULL)
- {
- fODCanvas->ReleasePlatformCanvas(ev);
- fPlatformCanvas = NULL;
- }
- #endif
-
- fODCanvas = newCanvas;
-
- #ifdef FW_BUILD_WIN
- fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODWindows);
- #endif
- #ifdef FW_BUILD_MAC
- fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODQuickDraw);
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::MappingChanged
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::MappingChanged(Environment* ev)
- {
- // ----- Set the origin offset -----
- UpdateOriginForContext(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::UpdateOriginForContext
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::UpdateOriginForContext(Environment* ev)
- {
- FW_CPlatformPoint offsetOrigin;
- FW_PrivGC_GetOriginOffset(ev, *fContext, offsetOrigin);
- FW_FailOnEvError(ev);
-
- offsetOrigin.Set(-offsetOrigin.X(), -offsetOrigin.Y());
-
- SetOrigin(ev, offsetOrigin);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetOrigin
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SetOrigin(Environment* ev, FW_CPlatformPoint origin)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- #ifdef FW_BUILD_WIN
- ::SetWindowOrgEx(fPlatformCanvas, origin.x, origin.y, NULL);
- #endif
- #ifdef FW_BUILD_MAC
- GrafPtr curPort;
- ::GetPort(&curPort);
-
- FW_CPlatformPoint oldOrigin(curPort->portRect.left, curPort->portRect.top);
- if(oldOrigin.h != origin.h || oldOrigin.v != origin.v)
- {
- // Set the port origin
- ::SetOrigin(origin.h, origin.v);
-
- // Shift the clip region
- ODRgnHandle rgn = GetClip();
- ::OffsetRgn(rgn, origin.h - oldOrigin.h, origin.v - oldOrigin.v);
- this->SetClip(ev, rgn);
- ::FW_DisposeRegion(rgn);
- }
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetClip
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SetClip(Environment* ev, ODRgnHandle clipRegion)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- #ifdef FW_BUILD_WIN
- ::SelectClipRgn(fPlatformCanvas, clipRegion);
- #endif
- #ifdef FW_BUILD_MAC
- if (fMacPostScriptClip)
- MacEndPostScriptClip();
-
- if (FW_MacIsColorPort(FW_QDGlobals.thePort)) // [LW7]
- {
- ::SetClip(clipRegion); // SetClip copies the region
- }
-
- if (fODCanvas != NULL && fODCanvas->HasPlatformPrintJob(ev, kODQuickDraw))
- {
- #define bDevLaser 3 // copied from "PrPrivate.a"
-
- THPrint thPrint = (THPrint) fODCanvas->GetPlatformPrintJob(ev, kODQuickDraw);
- FW_Boolean bPostScript = (((**thPrint).prStl.wDev >> 8) == bDevLaser);
-
- if (bPostScript && (*clipRegion)->rgnSize != 10)
- {
- // If the region is not rectangular
- MacBeginPostScriptClip(ev, clipRegion);
- }
- }
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::GetClip
- //---------------------------------------------------------------------------------------
-
- ODRgnHandle FW_CPrivGraphicsDevice::GetClip() const
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- ODRgnHandle clipHandle = FW_NewRegion();
- #ifdef FW_BUILD_WIN
- ::GetClipRgn(fPlatformCanvas, clipHandle);
- #endif
- #ifdef FW_BUILD_MAC
- ::GetClip(clipHandle);
- #endif
-
- return clipHandle;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetClipRect
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SetClipRect(const FW_CPlatformRect& clipRect)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- #ifdef FW_BUILD_WIN
- ODRgnHandle clipRegion = ::CreateRectRgnIndirect(&clipRect);
- ::SelectClipRgn(fPlatformCanvas, clipRegion);
- ::DeleteObject(clipRegion);
- #endif
- #ifdef FW_BUILD_MAC
- if (fMacPostScriptClip)
- MacEndPostScriptClip();
-
- ::ClipRect(&clipRect);
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::IntersectClipRect
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::IntersectClipRect(Environment* ev, const FW_CPlatformRect& clipRect)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- #ifdef FW_BUILD_WIN
- ::IntersectClipRect(fPlatformCanvas,
- clipRect.left, clipRect.top,
- clipRect.right, clipRect.bottom);
- #endif
- #ifdef FW_BUILD_MAC
- if (fMacPostScriptClip)
- MacEndPostScriptClip();
-
- ODRgnHandle rgn = ::FW_NewRegion();
- ::RectRgn(rgn, &clipRect);
- ODRgnHandle curClip = GetClip();
- ::SectRgn(curClip, rgn, curClip);
- ::FW_DisposeRegion(rgn);
- this->SetClip(ev, curClip);
- ::FW_DisposeRegion(curClip);
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::GetClipRect
- //---------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::GetClipRect(FW_CPlatformRect& clipRect) const
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- #ifdef FW_BUILD_WIN
- ::GetClipBox(fPlatformCanvas, &clipRect);
- #endif
- #ifdef FW_BUILD_MAC
- clipRect = (*FW_QDGlobals.thePort->clipRgn)->rgnBBox;
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetInGrafPort
- //----------------------------------------------------------------------------------------
- // [HLX] Maybe it is as fast to just set than testing and setting???
-
- void FW_CPrivGraphicsDevice::SetInGrafPort()
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT((fOpenDeviceCount != 0) && (fPlatformCanvas == FW_QDGlobals.thePort));
-
- RGBColor macColor;
-
- if (fChangeFlag & FW_kForeColorChanged)
- {
- macColor = fForeColor;
- ::RGBForeColor(&macColor);
- }
-
- if (fChangeFlag & FW_kBackColorChanged)
- {
- macColor = fBackColor;
- ::RGBBackColor(&macColor);
- }
-
- if (fChangeFlag & FW_kHiliteColorChanged)
- {
- macColor = fHiliteColor;
- ::HiliteColor(&macColor);
- }
-
- if (fChangeFlag & FW_kPatternChanged)
- fPattern->MacSetInCurPort();
-
- if (fPlatformCanvas->pnSize.h != fHPenSize || fPlatformCanvas->pnSize.v != fVPenSize)
- ::PenSize(fHPenSize, fVPenSize);
-
- if (fPlatformCanvas->txFont != fFontID)
- ::TextFont(fFontID);
-
- if (fPlatformCanvas->txSize != fFontSize)
- ::TextSize(fFontSize);
-
- if (fPlatformCanvas->txFace != fFontStyle)
- ::TextFace(fFontStyle);
-
- if (fPlatformCanvas->pnMode != fPenMode)
- ::PenMode(fPenMode);
-
- if (fPlatformCanvas->txMode != fTextMode)
- ::TextMode(fTextMode);
-
- fChangeFlag = 0;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::ResetSettings
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::ResetSettings()
- {
- FW_ASSERT((fPlatformCanvas == FW_QDGlobals.thePort));
-
- RGBColor macColor;
-
- ::GetForeColor(&macColor);
- fForeColor = macColor;
-
- ::GetBackColor(&macColor);
- fBackColor = macColor;
-
- LMGetHiliteRGB(&macColor);
- ::HiliteColor(&macColor);
- fHiliteColor = macColor;
-
- fPattern = FW_NEW(FW_CPrivBWPatternRep, (FW_kBlackPat));
- fPattern->MacSetInCurPort();
-
- fHPenSize = fPlatformCanvas->pnSize.h;
- fVPenSize = fPlatformCanvas->pnSize.v;
- fFontID = fPlatformCanvas->txFont;
- fFontSize = fPlatformCanvas->txSize;
- fFontStyle = fPlatformCanvas->txFace;
- fPenMode = fPlatformCanvas->pnMode;
- fTextMode = fPlatformCanvas->txMode;
-
- fChangeFlag = 0;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SelectInk
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SelectInk(const FW_HInk ink,
- FW_EPrivShapeCategories shapeCategory,
- FW_ERenderVerbs renderVerb)
- {
- FW_ASSERT(ink != NULL);
-
- FW_CColor foreColor, backColor;
- FW_TransferModes transferMode = ink->GetTransferMode();
-
- ink->GetForeColor(foreColor);
- ink->GetBackColor(backColor);
-
- if (transferMode == FW_kHilite)
- SetHiliteColor(foreColor);
- else if (transferMode == FW_kSystemHilite)
- {
- RGBColor macColor;
- LMGetHiliteRGB(&macColor);
- FW_CColor hiliteColor(macColor);
- SetHiliteColor(hiliteColor);
- }
-
- switch (shapeCategory)
- {
- case FW_kLineShape:
- if (transferMode == FW_kErase)
- {
- SetForeColor(backColor);
- SetBackColor(backColor);
- SetPenMode(FW_PrivMacGetMacTransferMode(transferMode));
- }
- else if (transferMode == FW_kInvert)
- {
- SetForeColor(foreColor);
- SetBackColor(backColor);
- SetPenMode(patXor);
- }
- else
- {
- SetForeColor(foreColor);
- SetBackColor(backColor);
- SetPenMode(FW_PrivMacGetMacTransferMode(transferMode));
- }
- break;
-
- case FW_kGeometricShape:
- if (renderVerb == FW_kFrame)
- {
- if (transferMode == FW_kErase)
- {
- SetForeColor(backColor);
- SetBackColor(backColor);
- SetPenMode(patCopy);
- }
- else if (transferMode == FW_kInvert)
- {
- SetForeColor(foreColor);
- SetBackColor(backColor);
- SetPenMode(patXor);
- }
- else
- {
- SetForeColor(foreColor);
- SetBackColor(backColor);
- SetPenMode(FW_PrivMacGetMacTransferMode(transferMode));
- }
- break;
- }
- else
- {
- SetForeColor(foreColor);
- SetBackColor(backColor);
- if (transferMode == FW_kInvert || transferMode == FW_kErase)
- SetPenMode(patCopy); // I will use ::InvertXXX or ::EraseXXX
- else
- SetPenMode(FW_PrivMacGetMacTransferMode(transferMode));
- }
-
- break;
-
- case FW_kTypographicShape:
- SetBackColor(backColor);
- if (transferMode == FW_kInvert)
- {
- SetForeColor(foreColor);
- SetTextMode(patXor);
- }
- else if (transferMode == FW_kErase)
- {
- SetForeColor(backColor);
- SetTextMode(patCopy);
- }
- else
- {
- SetForeColor(foreColor);
- SetTextMode(FW_PrivMacGetMacTransferMode(transferMode));
- }
- break;
-
- case FW_kImageShape:
- SetForeColor(foreColor);
- SetBackColor(backColor);
- // SetPenMode(FW_PrivMacGetMacTransferMode(transferMode)); // Not used on both patform
- break;
- }
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SelectStyle
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SelectStyle(const FW_HStyle style,
- FW_TransferModes transferMode,
- FW_Boolean& styleIsDash,
- FW_Boolean& styleIsHairline)
- {
- FW_ASSERT((const void*)style != NULL);
-
- if (transferMode == FW_kInvert || transferMode == FW_kErase)
- SetPattern(FW_CPattern(FW_kBlackPat));
- else
- SetPattern(style->GetPattern());
-
- FW_EStyleDash dash = style->GetDashStyle();
- FW_Fixed penSize = style->GetPenSize();
-
- FW_CPlatformPoint plfmPt;
- if (penSize == FW_kFixed0)
- {
- plfmPt.Set(1, 1);
-
- styleIsHairline = true;
- }
- else
- {
- Environment *ev = fContext->fEnvironment;
- FW_PrivGC_LogicalToDeviceSize(ev, *fContext, penSize, penSize, plfmPt);
- FW_FailOnEvError(ev);
-
- if (plfmPt.h == 0)
- plfmPt.h = 1;
-
- if (plfmPt.v == 0)
- plfmPt.v = 1;
-
- styleIsHairline = false;
- }
-
- SetPenSize(plfmPt.h, plfmPt.v);
-
- styleIsDash = dash != FW_kSolidLine && plfmPt.h <= 1 && plfmPt.v <= 1;
- }
-
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetPattern
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SetPattern(const FW_HPattern pattern)
- {
- fPattern = (FW_CPrivPatternRep*) pattern;
- fChangeFlag |= FW_kPatternChanged;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
-
- #define kPostScriptBegin 190 // Picture-comments for PostScript printing
- #define kPostScriptEnd 191
- #define kTextIsPostScript 194
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::MacBeginPostScriptClip
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::MacBeginPostScriptClip(Environment* ev, RgnHandle rgn)
- {
- FW_ASSERT(!fMacPostScriptClip);
-
- // In order for the PostScript commands we'll be emitting below to sync up
- // properly with other PS code the driver emits, we have to get something else
- // to emit right now as a flush. So we'll draw a tiny rectangle and make sure
- // it falls outside the clipping bounds.
-
- Rect bbox = (*rgn)->rgnBBox;
-
- Rect r;
- r.right = bbox.left;
- if (r.right == -32767)
- r.right = bbox.right + 1;
- r.bottom = bbox.top;
- if (r.bottom == -32767)
- r.bottom = bbox.bottom + 1;
- r.left = r.right - 1;
- r.top = r.bottom - 1;
- ::PaintRect(&r);
-
- // Copy a region to a shape so it can be converted to a polygon
- RgnHandle rgnCopy = ::FW_NewRegion();
- ::CopyRgn(rgn, rgnCopy);
- ODShape* shape = FW_NewODShape(ev, rgnCopy);
-
- // Now emit the polygon as a PostScript path and clip to it
- ODPolygon poly;
- shape->CopyPolygon(ev, &poly);
-
- ::PicComment(kPostScriptBegin, 0, kODNULL);
- ::PicComment(kTextIsPostScript, 0, kODNULL);
-
- ::DrawString("\ppse gsave"); // Cancels out the 'psb' generated by the LW driver
- ::DrawString("\pnewpath");
-
- char buf[128];
- ODContour* cont = poly.FirstContour();
- for (long n = poly.GetNContours(); n > 0; -- n, cont = cont->NextContour())
- {
- const ODPoint* v = cont->vertex;
- long m = cont->nVertices;
- if (m > 2)
- {
- ::DrawText(buf, 0,
- sprintf(buf, "%.2f %.2f moveto", ODFixedToFloat(v->x), ODFixedToFloat(v->y)));
-
- while (--m > 0)
- {
- ++ v;
- ::DrawText(buf, 0,
- sprintf(buf,"%.2f %.2f lineto", ODFixedToFloat(v->x), ODFixedToFloat(v->y)));
- }
- }
- }
-
- ::DrawString("\pclosepath clip"); // Adding newpath would be nice but LW7 no likee
-
- ::DrawString("\ppsb"); // Cancels out the forthcoming 'pse'
- ::PicComment(kPostScriptEnd, 0,kODNULL);
-
- shape->Release(ev);
-
- fMacPostScriptClip = TRUE;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::MacEndPostScriptClip
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::MacEndPostScriptClip()
- {
- FW_ASSERT(fMacPostScriptClip);
-
- PicComment(kPostScriptBegin, 0,kODNULL);
- PicComment(kTextIsPostScript, 0,kODNULL);
- DrawString("\ppse currentpoint grestore moveto psb");
- PicComment(kPostScriptEnd, 0,kODNULL);
-
- fMacPostScriptClip = FALSE;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SelectFont
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SelectFont(const FW_HFont font, FW_Boolean scale)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- FW_ASSERT((const void*)font != NULL);
-
- #ifdef FW_BUILD_WIN
- FW_CString255 fontName;
- font->GetFontName(fontName);
- char szFontName[256];
- fontName.ExportCString(szFontName);
- fGDIFont.SetFontName(szFontName);
- fGDIFont.SetFontStyle(font->GetFontStyle());
- #endif
- #ifdef FW_BUILD_MAC
- SetFontID(font->MacGetFontID());
- SetFontStyle(font->MacGetFontStyle());
- #endif
-
- FW_Fixed fontSize = font->GetFontSize();
- if (scale)
- {
- FW_CPlatformPoint pt;
- Environment* ev = fContext->fEnvironment;
- FW_PrivGC_LogicalToDeviceSize(ev, *fContext, fontSize, fontSize, pt);
- FW_FailOnEvError(ev);
- fontSize = FW_IntToFixed(pt.Y());
- }
-
- #ifdef FW_BUILD_WIN
- fGDIFont.SetFontSize(FW_FixedToInt(fontSize));
- fGDIFont.SelectObject(fPlatformCanvas);
- #endif
- #ifdef FW_BUILD_MAC
- SetFontSize(FW_FixedToInt(fontSize));
- SetInGrafPort();
- #endif
- }
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SelectInkAndFont
- //----------------------------------------------------------------------------------------
- // Only call for Text shapes
-
- void FW_CPrivGraphicsDevice::SelectInkAndFont(const FW_HInk ink, const FW_HFont font)
- {
- SetTextColor(ink->GetForeColor());
- SetBkColor(ink->GetBackColor());
- SetBkMode(ink->GetTransferMode() == FW_kOr ? TRANSPARENT : OPAQUE);
-
- SelectFont(font, TRUE);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetTextColor
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SetTextColor(COLORREF textColor)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- if (fTextColor != textColor)
- {
- fTextColor = textColor;
- ::SetTextColor(fPlatformCanvas, textColor);
- }
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SetBkColor
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGraphicsDevice::SetBkColor(COLORREF bkColor)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- if (fBkColor != bkColor)
- {
- fBkColor = bkColor;
- ::SetBkColor(fPlatformCanvas, bkColor);
- }
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivGraphicsDevice::SelectInkAndStyle
- //----------------------------------------------------------------------------------------
- // Only call for shapeCategory == FW_kGeometricShape or FW_kGeometricShapeWithInvert
-
- FW_Boolean FW_CPrivGraphicsDevice::SelectInkAndStyle(const FW_HInk ink,
- const FW_HStyle style,
- FW_EPrivShapeCategories shapeCategory,
- FW_ERenderVerbs renderVerb)
- {
- FW_ASSERT(!fSuspended);
- FW_ASSERT(fOpenDeviceCount != 0);
-
- FW_CHECK_PLATFORM_CANVAS
-
- FW_ASSERT((const void*)ink != NULL);
- FW_ASSERT((const void*)style != NULL);
-
- FW_Boolean frameWithBrush = FALSE;
-
- // ----- Set transfer mode -----
- if (shapeCategory == FW_kGeometricShapeWithInvert &&
- ink->GetTransferMode() == FW_kInvert ||
- ink->GetTransferMode() == FW_kHilite ||
- ink->GetTransferMode() == FW_kSystemHilite)
- {
- SetDrawingMode(R2_COPYPEN);
- }
- else
- SetDrawingMode(::PrivWinROP2(ink->GetTransferMode()));
-
- // ----- Set pen size (even if filling)
- FW_Fixed penSize = style->GetPenSize();
- if (penSize == FW_kFixed0)
- fPenSize.Set(1,1);
- else
- FW_PrivGC_LogicalToDeviceSize(*fContext, penSize, penSize, fPenSize);
-
- // ----- Set pen and brush -----
- int nBkMode = OPAQUE;
- if (renderVerb == FW_kFrame)
- {
- FW_EStyleDash dash = style->GetDashStyle();
- frameWithBrush = (dash == FW_kSolidLine) &&
- (!ink->PrivSpecialTransferMode()) &&
- (!style->GetPattern()->IsBlack());
-
- if (frameWithBrush)
- {
- // NOTE: I don't set the Pen because we will not use it
-
- // ----- Set foreground and background Color -----
- SetTextColor(ink->GetForeColor());
- SetBkColor(ink->GetBackColor());
-
- // ----- Set Brush -----
- fGDIBrush.SetBrushPattern(style->GetPattern());
- }
- else
- {
- // ----- Set the Brush -----
- fGDIBrush.SetStockID(NULL_BRUSH);
-
- // ----- Set the pen -----
- fGDIPen.SetPenSize(fPenSize.y);
- fGDIPen.SetPenStyle(dash);
- fGDIPen.SetPenColor(ink->GetTransferMode() == FW_kErase ? ink->GetBackColor() : ink->GetForeColor());
-
- if ((dash & FW_kOpaque) == 0)
- nBkMode = TRANSPARENT;
- else
- SetBkColor(ink->GetBackColor());
- }
- }
- else
- {
- // ----- Set the pen -----
- fGDIPen.SetStockID(NULL_PEN);
-
- // ----- Set the Brush -----
- FW_TransferModes transferMode = ink->GetTransferMode();
- if (transferMode == FW_kErase)
- {
- SetTextColor(RGB(0x00, 0x00, 0x00));
- SetBkColor(RGB(0xFF, 0xFF, 0xFF));
- fGDIBrush.SetBrushColor(ink->GetBackColor());
- }
- else if (transferMode == FW_kInvert || transferMode == FW_kHilite || || transferMode == FW_kSystemHilite)
- {
- SetTextColor(RGB(0x00, 0x00, 0x00));
- SetBkColor(RGB(0xFF, 0xFF, 0xFF));
- fGDIBrush.SetStockID(BLACK_BRUSH);
- }
- else
- {
- const FW_PPrivPattern pattern = style->GetPattern();
-
- if (pattern->IsBlack())
- {
- // If pattern is black let just use a solid brush
- SetTextColor(RGB(0x00, 0x00, 0x00));
- SetBkColor(RGB(0xFF, 0xFF, 0xFF));
- fGDIBrush.SetBrushColor(ink->GetForeColor());
- }
- else
- {
- SetTextColor(ink->GetForeColor());
- SetBkColor(ink->GetBackColor());
- fGDIBrush.SetBrushPattern(pattern);
- }
- }
- }
-
- SetBkMode(nBkMode);
-
- if (!frameWithBrush)
- {
- fGDIPen.SelectObject(fPlatformCanvas);
- fGDIBrush.SelectObject(fPlatformCanvas);
- }
-
- return frameWithBrush;
- }
- #endif
-